package jianzhiOffer;
//剑指 Offer 55 - II. 平衡二叉树
public class Num55_II_isBalanced {
    public boolean isBalanced(TreeNode root) {
        if (root == null){
            return true;
        }else {
            return Math.abs(height(root.left)-height(root.right))<=1 && isBalanced(root.left) && isBalanced(root.right);
        }

    }
    //二叉树的深度
    public int height(TreeNode root){
        if (root == null){
            return 0;
        }else {
            return 1+Math.max(height(root.left),height(root.right));
        }
    }
}
